package com.solution.admin.customer.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.solution.admin.customer.dao.CompanyExpressConfigAddressDao;
import com.solution.admin.customer.entity.CompanyExpressConfigAddressEntity;
import com.solution.common.dao.impl.BaseDaoImpl;
import com.solution.common.page.PageBean;
import com.solution.common.page.PageParam;

/**
 * 公司常用物流配置-地址列表DAO实现
 * @author solin
 * @date 2018-03-22 18:51:24
 */
@Repository
public class CompanyExpressConfigAddressDaoImpl extends BaseDaoImpl<CompanyExpressConfigAddressEntity> implements CompanyExpressConfigAddressDao {
	@Autowired
	SqlSessionTemplate sqlSessionTemplate;
	
	/**
	 * 保存公司常用物流配置-地址列表信息
	 * @param companyExpressConfigAddressEntity
	 * @return
	 * @author solin
	 * @date 2018-03-22 18:51:24
	 */
	@Override
	public long saveCompanyExpressConfigAddress(CompanyExpressConfigAddressEntity companyExpressConfigAddressEntity) {
		return super.insert(companyExpressConfigAddressEntity);
	}
	
	@Override
	public long saveCompanyExpressConfigAddress(List<CompanyExpressConfigAddressEntity> companyExpressConfigAddressList) {
		return super.insert(companyExpressConfigAddressList);
	}

	/**
	 * 分页查询公司常用物流配置-地址列表信息
	 * @param pageParam 分页对象
	 * @param companyExpressConfigAddress 分页参数
	 * @return PageBean 分页参数及数据
	 * @author solin
	 * @date 2018-03-22 18:51:24
	 */
	public PageBean listCompanyExpressConfigAddressPage(PageParam pageParam, Map<String, Object> param) {
		return super.listPage(pageParam, param);
	}

	/**
	 * 更新公司常用物流配置-地址列表
	 * @param companyExpressConfigAddressEntity
	 * @return
	 * @author solin
	 * @date 2018-03-22 18:51:24
	 */
	@Override
	public int updateCompanyExpressConfigAddress(CompanyExpressConfigAddressEntity companyExpressConfigAddressEntity) {
		return super.update(companyExpressConfigAddressEntity);
	}

	/**
	 * 删除公司常用物流配置-地址列表
	 * @param companyExpressConfigAddressId
	 * @return
	 * @author solin
	 * @date 2018-03-22 18:51:24
	 */
	public int deleteCompanyExpressConfigAddressById( Long id) {
		return super.deleteById(id);
	}
	
	public int deleteCompanyExpressConfigAddressByCompanyId( Long companyId) {
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("companyId", companyId);
		return sqlSessionTemplate.delete("deleteCompanyExpressConfigAddressByCompanyId", paramMap);
	}
	
	/**
	 * 根据条件查询公司常用物流配置-地址列表
	 * @param param
	 * @return
	 * @author solin
	 * @date 2018-03-22 18:51:24
	 */
	@Override
	public List<CompanyExpressConfigAddressEntity> listCompanyExpressConfigAddress( Map<String, Object> param) {
		return super.listBy(param);
	}

	/**
	 * 查询该公司地址是否免运费
	 * @param paramMap
	 * @return
	 * @author xkl
	 * @date 2018年3月23日 下午4:54:11
	 */
	@Override
	public int countByCompanyIdAndAddressId(Map<String, Object> paramMap) {
		return getSessionTemplate().selectOne("countByCompanyIdAndAddressId", paramMap);
	}

	/**
	 * 删除公司免运费地址记录
	 * @param paramMap
	 * @return
	 * @author xkl
	 * @date 2018年3月23日 下午5:14:47
	 */
	@Override
	public int removeFreeAddressInfo(Map<String, Object> paramMap) {
		return sqlSessionTemplate.delete("removeFreeAddressInfo", paramMap);
	}
}
